home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9174 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.3 KB  |  67 lines

  1. Path: library.erc.clarkson.edu!rpi!not-for-mail
  2. From: "john (j.d.) hickin" <hickin@bnr.ca>
  3. Newsgroups: comp.lang.c++,comp.lang.c++.moderated
  4. Subject: Re: Argc & Argv
  5. Date: 28 Feb 1996 15:01:46 -0000
  6. Organization: Nortel Technology
  7. Sender: cppmods@netlab.cs.rpi.edu
  8. Approved: Dietmar.Kuehl@uni-konstanz.de
  9. Message-ID: <4h1qoq$8kh@netlab.cs.rpi.edu>
  10. References: <4gta9f$df5@netlab.cs.rpi.edu>
  11. NNTP-Posting-Host: netlab.cs.rpi.edu
  12. X-Original-Date: Tue, 27 Feb 1996 14:19:57 -0500
  13.  
  14. Rick Richert wrote:
  15. > >>  I tried posting this last week and am not sure if it was posted or
  16. > >>  not.  Soooo, I'm trying again.
  17. > I have some global objects defined outside the main routine and I would
  18. > like to pass the argc and argv values to their constructors.  For example,
  19. > SomeClass obj( argc, argv);
  20. > int main( int argc, char **argv) {
  21. >    blah, blah, blah
  22. > }
  23. > Unfortunately, the compiler tells me that argc and argv are not defined
  24. > or else not available for obj.
  25. > Currently, I get around this problem by creating the global obj and then
  26. > inside of main, I initialize obj via a method that takes argc and argv.
  27. > I would prefer to pass the arg vars to the constructor.  Does anyone know
  28. > how I can pass the arg vars without being inside of main?
  29. >       [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
  30. >       [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
  31. >       [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
  32. >       [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
  33.  
  34. Some systems let you get at argc/argv before main() but portable code
  35. can't use
  36. that approach.
  37.  
  38. An alternative to consider is the use of a data file to specify your
  39. arguments
  40. in.  Put the data file's path name in a known environment variable.
  41. Make the
  42. data file format exactly the same as your command line format.  Then you
  43. can
  44. specify 'pre-main' args independently of 'main-args', etc.  This
  45. approach is
  46. especially useful for controlling trace objects dynamically.
  47.  
  48. -- 
  49. John Hickin      Nortel Technology, Montreal, Quebec
  50. (514) 765-7924   hickin@bnr.ca
  51.  
  52.       [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
  53.       [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
  54.       [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
  55.       [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
  56.